package todo;

import se.lth.cs.realtime.semaphore.Semaphore;
import done.ClockOutput;

public class TimeHandler extends Thread {
	private static ClockOutput output;
	long clockTime, t, diff;
	SharedData sharedData;
	private Semaphore tick;
	
	public TimeHandler(ClockOutput output, SharedData sharedData){
		this.output = output;
		this.sharedData = sharedData;
		sharedData.setClockTime(System.currentTimeMillis());
		
	}
	
	public void run(){
		try{
			t = System.currentTimeMillis();
			
			while(true){
				sharedData.incClockTime();
				t += 1000;
				diff = t - System.currentTimeMillis();
				if (diff > 0){
					Thread.sleep(diff);
				}
				
			}
			
		}
		catch (Exception e) {
			// TODO: handle exception
		}
		
	}
}
